//
//  Daltonizer.h
//  iSeeColor
//
//  Created by Galen Marisco on 10/20/12.
//  Copyright (c) 2012 Wyatt Gosling. All rights reserved.
////

#import <Foundation/Foundation.h>
#include <Accelerate/Accelerate.h>
#include <CoreGraphics/CoreGraphics.h>

// This class handles the daltonization of images from the imageLibrary.
@interface Daltonizer : NSObject

@property (nonatomic) NSUInteger imageSize;


/*
 Description: This function will perform a color transformation on a bitmap.
 Args: float array of rgba values to be transformed, transformation matrix.
 Purpose: for moving the picture between different color spaces, such as rgb -> lms, lms->rgb, etc.
 Returns: float array of rgba values
 Pre: n/a
 Post: n/a
 
 */
- (float*) transformColorspace:(float*) bitmap :(float*) transformVector;


/*
 Description: This method subtracts two bitmaps and returns the difference.
 Args: rawBitmap is the orgiginal which we calculate the difference from colorblindBitmap
 Purpose: to produce the error image, ie the colors that the colorblind person cannot see.
 Returns: float array of rgba values
 Pre: n/a
 Post: n/a
 
 */
- (float*) calculateError:(float*) rawBitmap:(float*) colorblindBitmap;


/*
 Description: This method blends the shifted error bitmap with the original bitmap to produce the daltonized image.
 Args: rawBitmap is the orgiginal and shiftedError is the error which has been shifted up in the spectrum.
 Purpose: merge the newly 'seeable' colors with the original image.
 Returns: float array of rgba values
 Pre: n/a
 Post: n/a
 
 */
- (float*) correctForShiftedError:(float*) rawBitmap:(float*) shiftedError;


/*
 Description: This method casts the character array bitmap of the image to a float array.
 Args: character array charBitmap
 Purpose: to be used initially so that arithmetic can be performed on the array.
 Returns: float array of rgba values
 Pre: n/a
 Post: n/a
 
 */
- (float*) convertCharToFloat:(unsigned char*) charBitmap;


/*
 Description: This method casts the float array bitmap of the image to a character array.
 Args: float array floatBitmap
 Purpose: to be used at the end of the algorithm to convert back to the character array that needs to be returned.
 Returns: character array of rgba values
 Pre: n/a
 Post: n/a
 
 */
- (unsigned char*) convertFloatToChar:(float*) floatBitmap;

// Print float values of the pixel information, for dedugging purposes.
- (void) printFloatArray:(float*) array;

// Print character values of the pixel information, for debugging purposes.
- (void) printCharArray:(char*) array;

// Send bitmap through daltonization algorithm.
- (unsigned char*) daltonizeBitmap:(unsigned char*) charBitmap;

//define the correction matrix based on the type of colorblindness
-(float*)defineCorrection:(float*)correctionMatrix:(int)typeOfCB:(float)Intensity;

//create the RGB to LMS correction matrix for a certain type of colorblindness
- (float*)defineCB:(float*)LMScolorMatrix:(int)typeOfCB:(float)Intensity;

/*
 description: the main algorithm to transform an image to compensate for red-green color blindness.
 args: theImage is an image either taken with the camera or from the photoLibrary
 return: returns the transformed UIImage theImage.
 pre: theImage must be a valid image.
 post: the original theImage is not altered.
 */
- (UIImage*) daltonize:(UIImage*) image;



@end
